﻿using System;
using Prism.Ioc;
using System.Linq;
using Prism.Commands;
using AvalonDock.Themes;
using FrameWork.Core.Base;
using System.Windows.Input;
using FrameWork.Core.Resources;
using System.Collections.Generic;
using FrameWork.Core.Infrastructure;
using FrameWork.Core.Adapter.Device;
using System.Collections.ObjectModel;
using FrameWork.Core;
using FrameWork.Data.Interface;
using FrameWork.Data.Mapping;
using FrameWork.Language;
using FrameWork.Services;
using FrameWork.Core.Enum;
using Anche.Module.Main.MessageEvent;

namespace AncheStart
{
    public class MainWindowVm : ViewModelBase
    {
        public override string Title => SystemSettingManagerConfig.ProgramName;

        #region ___字段___

        private IContainerExtension _Container;
        private Tuple<string, Theme> selectedTheme;

        #endregion ___字段___

        #region ___构造函数___

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="containerProvider"></param>
        public MainWindowVm(IContainerExtension containerProvider) : base(containerProvider)
        {
        }

        #endregion ___构造函数___

        #region ___绑定方法___

        /// <summary>
        /// 页面加载完成
        /// </summary>
        public new ICommand LoadedCommand => new DelegateCommand(() =>
        {
            InitPageData();
        });

        public new ICommand UnLoadedCommand => new DelegateCommand(() =>
        {
            //退出曲线查看软件
        });

        #endregion ___绑定方法___

        #region ___类内方法___
        /// <summary>
        /// 初始化页面
        /// </summary>
        private void InitPageData()
        {
            try
            {
                SystemSetting systemSetting = EngineContext.Current.Resolve<ISystemSettingManager>().getFirstOrDefault();
                if (systemSetting.LanguageType == (int)LanguageType.ZhTw)
                {
                    GlobalConstant.LanguageType = LanguageType.ZhTw;
                    I18n.ChangeLanguage(LanguageType.ZhTw);
                }
                else if (systemSetting.LanguageType == (int)LanguageType.ZhCn)
                {
                    GlobalConstant.LanguageType = LanguageType.ZhCn;
                    I18n.ChangeLanguage(LanguageType.ZhCn);
                }
                else
                {
                    GlobalConstant.LanguageType = LanguageType.En;
                    I18n.ChangeLanguage(LanguageType.En);
                }


                Enum.TryParse<EnumChannelStyle>(systemSetting.ChannelStyle.ToString(), out EnumChannelStyle result);
                GlobalConstant.ChannelStyle = result;
            }
            catch (Exception ex)
            {
                m_EventAggregator.GetEvent<LogMessageEvent>().Publish(new LogMessageEvent() { CreateTime = DateTime.Now, LogContent = ex.Message });
           
            }
           
        }
        #endregion ___类内方法___
    }
}